<?php
/*
 * @Author: your name
 * @Date: 2021-02-22 12:51:29
 * @LastEditTime: 2021-02-23 19:02:48
 * @LastEditors: your name
 * @Description: In User Settings Edit
 * @FilePath: \lh_vue\awesomepos\php\goods.php
 */
//  指定允许其他域名访问
header('Access-Control-Allow-Origin:*');
// 响应类型
header('Access-Control-Allow-Methods:GET, POST, OPTIONS');
// 响应头设置
header('Access-Control-Allow-Credentials:false');
header("Access-Control-Allow-Headers:Content-Type,XFILENAME,XFILECATEGORY,XFILESIZE");

require_once 'Db.php';

//获取产品列表
function getGoodsList(){
    $db = new Db();
    $my_db = $db->getDB();
    $_sql = "SELECT id,trade_name,true_price,cover,one_class FROM bd_goods WHERE supplier_id = 67 ORDER BY id DESC  LIMIT 20";
    $_result = $my_db->query($_sql);
    $_html = [];
    while(!!$objects = $_result->fetch_object()){
        $_html[] = $objects;
    }
    $db->unDB($_result,$my_db);
    return $_html;
}
//获取常用商品
$_good_list = getGoodsList();

//获取所需分类
//
function getCate(){
    $db = new Db();
    $my_db = $db->getDB();
    $_sql = "SELECT id,private_class_name,private_one_class FROM bd_private_cate WHERE private_class_belong = 0 AND supplier_id = 67 LIMIT 5";
    $_result = $my_db->query($_sql);
    $_html = [];
    while(!!$object = $_result->fetch_object()){
        $_html[] = $object;
    }
    $db->unDB($_result,$my_db);
    return $_html;
}

$_cate_list = getCate();


$data['GoodsList'] = $_good_list;
$data['cate_list'] = $_cate_list;
echo json_encode($data);